# 项目：python_project
# 文件：actions
# 作者：WuTong
# 日期：2025/5/21,16:30
# coding:utf-8
from time import sleep

from YunDuanBossUI_Test.tools import Util,UIAction as ui

class QuestionBankManagementAction:

    @classmethod
    def click_add_choices_button(cls,driver):
        add_choices_button = driver.find_element(*eval(cls.element_info['add_choices_button']))
        add_choices_button.click()

    @classmethod
    def select_direction(cls,driver):
        direction = driver.find_element(*eval(cls.element_info['direction']))
        ui.select_random(direction)

    @classmethod
    def select_stage(cls,driver):
        stage = driver.find_element(*eval(cls.element_info['stage']))
        ui.select_random(stage)

    @classmethod
    def select_course(cls,driver):
        course = driver.find_element(*eval(cls.element_info['course']))
        ui.select_random(course)

    @classmethod
    def input_question(cls,driver,data):
        question = driver.find_element(*eval(cls.element_info['question']))
        ui.write(question,data['econtent1'])

    @classmethod
    def input_choiceA(cls,driver,data):
        choiceA = driver.find_element(*eval(cls.element_info['choiceA']))
        ui.write(choiceA,data['A'])

    @classmethod
    def input_choiceB(cls, driver, data):
        choiceB = driver.find_element(*eval(cls.element_info['choiceB']))
        ui.write(choiceB, data['B'])

    @classmethod
    def input_choiceC(cls, driver, data):
        choiceC = driver.find_element(*eval(cls.element_info['choiceC']))
        ui.write(choiceC, data['C'])

    @classmethod
    def input_choiceD(cls, driver, data):
        choiceD = driver.find_element(*eval(cls.element_info['choiceD']))
        ui.write(choiceD, data['D'])

    @classmethod
    def click_right_choice(cls,driver):
        right_choice_button = driver.find_element(*eval(cls.element_info['right_choice']))
        right_choice_button.click()

    @classmethod
    def click_save_button(cls,driver):
        save_button = driver.find_element(*eval(cls.element_info['save_button']))
        save_button.click()

    @classmethod
    def click_error_msg(cls,driver):
        if ui.is_element_present(*eval(cls.element_info['error_msg'])):
            driver.find_element(*eval(cls.element_info['error_msg'])).click()
            actual = '添加失败'
            driver.refresh()
        else:
            actual = '添加成功'
            driver.refresh()
        return actual

    @classmethod
    def do_add_choice(cls, driver, data):
        cls.element_info = Util.read_ini('choices')
        cls.click_add_choices_button(driver)
        cls.select_direction(driver)
        cls.select_stage(driver)
        cls.select_course(driver)
        cls.input_question(driver,data)
        cls.input_choiceA(driver,data)
        cls.input_choiceB(driver,data)
        cls.input_choiceC(driver,data)
        cls.input_choiceD(driver,data)
        cls.click_right_choice(driver)
        cls.click_save_button(driver)
        sleep(3)
        return cls.click_error_msg(driver)

if __name__ == '__main__':
    pass